package com.google.code.lightsomy.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Searches annotated methods by annotation type.
 * 
 * @author Viktoras Agejevas
 *
 */
public class AnnotatedMethodSearch {

	public static Method getAnnotatedMethod(Object obj, Class<? extends Annotation> annotation) {
		for (Method m : obj.getClass().getMethods()) {
			if (m.isAnnotationPresent(annotation)) {
				return m;
			}
		}
		return null;
	}
	
	public static List<Method> getAnnotatedMethods(Object obj, Class<? extends Annotation> annotation) {
		List<Method> methods = new ArrayList<Method>();
		
		for (Method m : obj.getClass().getMethods()) {
			if (m.isAnnotationPresent(annotation)) {
				methods.add(m);
			}
		}
		return methods;
	}
	
	public static boolean hasAnnotatedMethod(Object obj, Class<? extends Annotation> annotation) {
		return getAnnotatedMethod(obj, annotation) != null;
	}
}
